﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace helicopterFight
{
    public class Missile : GameObject
    {
        public Game1 game;
        public Vector3 direction;
        private Boolean active = true;
        public Boolean Active
        {
            get { return active; }
            set { active = value; }
        }
        public float speed = 15f;
        public float distance = 5;
        private BoundingSphere missileSphere;
        private const float mSphereRadius = 10;
        private HelicopterObject owner;
        private bool ignore = false;
        private int launchTime;
        private const int DISCARD_TIME = 5;

        public bool Ignore
        {
            get { return ignore; }
            set { ignore = value; }
        }

        public HelicopterObject Owner
        {
            get { return owner; }
            set { owner = value; }
        }

        public BoundingSphere MissileSphere
        {
            get { return missileSphere; }
            set { missileSphere = value; }
        }

        public void init(Game1 gam, HelicopterObject owner)
        {
            game = gam;
            scale = 0.04f;
            this.owner = owner; 
            launchTime = owner.State.GameTime.TotalGameTime.Seconds;
            model = game.Content.Load<Model>("models/missile");
            HelicopterObject.missileDistance = distance;
            missileSphere = new BoundingSphere(position, mSphereRadius);
        }


        public void setPosition(Vector3 position)
        {
            this.position = position;
            missileSphere.Center = position;
            missileSphere.Radius = mSphereRadius;
        }

        public void setParams(Vector3 pos, Vector3 rot, Vector3 dir)
        {
            position = pos;
            rotation = rot;
            direction = dir;
        }

        public override void draw()
        {
            base.draw();
        }

        public override void update()
        {
            if (owner.State.GameTime.TotalGameTime.Seconds - launchTime > DISCARD_TIME)
            {
                active = false;
            }

            if (active)
            {
                position += direction;
                HelicopterObject.missileDistance += 3;
                missileSphere.Center = position;
                missileSphere.Radius = mSphereRadius;
            }
        }
    }
}
